package appletFour;


import globalCode.TableHandler;

import java.applet.Applet;
import java.awt.Color;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.BorderFactory;
import javax.swing.JTabbedPane;
import javax.swing.border.Border;



public class OverallApplet extends Applet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private OutputPanel output;

	@Override
	public void start(){
		this.setSize(650, 500);
		this.setVisible(true);
		Border b1 = BorderFactory.createLineBorder(Color.GRAY);
		
		JTabbedPane tabs = new JTabbedPane();
		tabs.setBorder(b1);
		this.add(tabs);

		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			return;
		}

		//String url = "jdbc:mysql://ischooldev.fcps.net";
		//String url = "jdbc:mysql://dosshome.dyndns-office.com:63306";
		//String url = "jdbc:mysql://192.168.1.33:3306";
		String url = "jdbc:mysql://localhost";
		String username = "root";
		String password = "PAss33word!!";
		Connection con = null;

		try {
			con = DriverManager.getConnection(url, username, password);
		} catch (SQLException e) {
			System.out.println("failed to connect");
			stop();
			return;
		}
		
		TableHandler th = new TableHandler(con);
		
		UCPanel ucp = new UCPanel(this, con);
		tabs.add(ucp, "User Connection");
		THPanel thp = new THPanel(this, con, th);
		tabs.add(thp, "Group Connection");
		RebuildPanel rbp = new RebuildPanel(this, con, th);
		tabs.add(rbp, "Rebuild Database");
		output = new OutputPanel(this);
		tabs.add(output, "Text Output");
		validate();
		repaint();
		
		//System.out.println("HI");
	}

	@Override
	public void stop(){
		System.exit(0);
	}

	public void output(String s){
		output.write(s);
	}

}
